package com.lagou.mr.homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 实现reduce阶段
 */
public class SortNumberReducer extends Reducer<IntWritable, NullWritable, IntWritable,IntWritable> {
    // 排名
    private int rank = 1;

    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //循环是为了对避免相同数值合并了
        for (NullWritable value : values) {
            //输出排名和对应的数值
            context.write(new IntWritable(rank),key);
            //对排名加1
            rank++;
        }
    }
}
